package com.example.griddemo.adapter;

import static androidx.constraintlayout.helper.widget.MotionEffect.TAG;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.griddemo.R;
import com.example.griddemo.viewmodel.Category;

import java.util.List;

public class CategoryAdapter extends BaseAdapter {
    private List<Category> categoryList;
    private Context ctx;
    public CategoryAdapter(Context ctx, List<Category> categoryList) {
        this.categoryList = categoryList;
        this.ctx = ctx;
    }

    @Override
    public View getView(int index, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(this.ctx).inflate(R.layout.category_list_item2, null);
            holder = new ViewHolder();
            holder.left_category_list_item = convertView.findViewById(R.id.left_category_list_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.left_category_list_item.setText(this.categoryList.get(index).getName());
        return convertView;
    }

    @Override
    public int getCount() {
        return this.categoryList == null ? 0 : this.categoryList.size();
    }

    @Override
    public Object getItem(int index) {
        return this.categoryList.get(index);
    }

    @Override
    public long getItemId(int index) {
        return index;
    }

    static class ViewHolder {
        public TextView left_category_list_item;
    }
}